/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.kungkhies.persistence.entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author clayton
 */
@Entity 
@Table(name = "kungkhie_knode")
@XmlRootElement
@NamedQueries(
{
    @NamedQuery(name = "KungkhieKnode.findAll", query = "SELECT k FROM KungkhieKnode k"),
    @NamedQuery(name = "KungkhieKnode.findByKungkhieId", query = "SELECT k FROM KungkhieKnode k WHERE k.kungkhieKnodePK.kungkhieId = :kungkhieId"),
    @NamedQuery(name = "KungkhieKnode.findByKnodeId", query = "SELECT k FROM KungkhieKnode k WHERE k.kungkhieKnodePK.knodeId = :knodeId")
})
public class KungkhieKnode implements Serializable 
{
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected KungkhieKnodePK kungkhieKnodePK;
    @JoinTable(name = "arc", joinColumns =
    {
        @JoinColumn(name = "kungkhie_id", referencedColumnName = "kungkhie_id"),
        @JoinColumn(name = "from_knode", referencedColumnName = "knode_id")
    }, inverseJoinColumns =
    {
        @JoinColumn(name = "kungkhie_id", referencedColumnName = "kungkhie_id"),
        @JoinColumn(name = "to_knode", referencedColumnName = "knode_id")
    })
    @ManyToMany
    private Collection<KungkhieKnode> kungkhieKnodeCollection;
    @ManyToMany(mappedBy = "kungkhieKnodeCollection")
    private Collection<KungkhieKnode> kungkhieKnodeCollection1;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "kungkhieKnode")
    private Collection<Polyhole> polyholeCollection;
    @JoinColumn(name = "knode_id", referencedColumnName = "knode_id", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Knode knode;
    @JoinColumn(name = "kungkhie_id", referencedColumnName = "kungkhie_id", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Kungkhie kungkhie;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "kungkhieKnode")
    private Collection<KnodeActivity> knodeActivityCollection;

    public KungkhieKnode()
    {
    }

    public KungkhieKnode(KungkhieKnodePK kungkhieKnodePK)
    {
        this.kungkhieKnodePK = kungkhieKnodePK;
    }

    public KungkhieKnode(long kungkhieId, long knodeId)
    {
        this.kungkhieKnodePK = new KungkhieKnodePK(kungkhieId, knodeId);
    }

    public KungkhieKnodePK getKungkhieKnodePK()
    {
        return kungkhieKnodePK;
    }

    public void setKungkhieKnodePK(KungkhieKnodePK kungkhieKnodePK)
    {
        this.kungkhieKnodePK = kungkhieKnodePK;
    }

    @XmlTransient
    public Collection<KungkhieKnode> getKungkhieKnodeCollection()
    {
        return kungkhieKnodeCollection;
    }

    public void setKungkhieKnodeCollection(Collection<KungkhieKnode> kungkhieKnodeCollection)
    {
        this.kungkhieKnodeCollection = kungkhieKnodeCollection;
    }

    @XmlTransient
    public Collection<KungkhieKnode> getKungkhieKnodeCollection1()
    {
        return kungkhieKnodeCollection1;
    }

    public void setKungkhieKnodeCollection1(Collection<KungkhieKnode> kungkhieKnodeCollection1)
    {
        this.kungkhieKnodeCollection1 = kungkhieKnodeCollection1;
    }

    @XmlTransient
    public Collection<Polyhole> getPolyholeCollection()
    {
        return polyholeCollection;
    }

    public void setPolyholeCollection(Collection<Polyhole> polyholeCollection)
    {
        this.polyholeCollection = polyholeCollection;
    }

    public Knode getKnode()
    {
        return knode;
    }

    public void setKnode(Knode knode)
    {
        this.knode = knode;
    }

    public Kungkhie getKungkhie()
    {
        return kungkhie;
    }

    public void setKungkhie(Kungkhie kungkhie)
    {
        this.kungkhie = kungkhie;
    }

    @XmlTransient
    public Collection<KnodeActivity> getKnodeActivityCollection()
    {
        return knodeActivityCollection;
    }

    public void setKnodeActivityCollection(Collection<KnodeActivity> knodeActivityCollection)
    {
        this.knodeActivityCollection = knodeActivityCollection;
    }

    @Override
    public int hashCode()
    {
        int hash = 0;
        hash += (kungkhieKnodePK != null ? kungkhieKnodePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object)
    {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof KungkhieKnode))
        {
            return false;
        }
        KungkhieKnode other = (KungkhieKnode) object;
        if ((this.kungkhieKnodePK == null && other.kungkhieKnodePK != null) || (this.kungkhieKnodePK != null && !this.kungkhieKnodePK.equals(other.kungkhieKnodePK)))
        {
            return false;
        }
        return true;
    }

    @Override
    public String toString()
    {
        return "com.kungkhies.persistence.entities.KungkhieKnode[ kungkhieKnodePK=" + kungkhieKnodePK + " ]";
    }

}
